package projet.item;

import projet.Tools;

import projet.CustomException;
import projet.dataaccess.DataAccess;
import projet.dataaccess.PathErrorException;

/**
 * The DVD class represents a DVD object. Information about the DVD is stored
 * and can be retrieved. We assume that we only deal with movie DVDs at this
 * stage.
 * 
 * @author CORSINI Pierre, BRUN Sylvain
 * @version December 13, 2009
 */
public class DVD extends Item {
	private String director;

	/**
	 * Create a DVD with the give id, with user input
	 * 
	 * @param id
	 * @throws CustomException
	 */
	public DVD(int id) throws CustomException {
		super();
		this.id = id;
		this.AskEdit();
	}

	/**
	 * Constructor for objects of class DVD
	 * 
	 * @param theTitle The title of this DVD.
	 * @param theDirector The director of this DVD.
	 * @param time The running time of the main feature.
	 */
	public DVD(int id, String theTitle, String comment, String theDirector) {
		super(id, theTitle, comment, null);
		this.director = theDirector;
	}

	public DVD(DataAccess dataAccess) throws PathErrorException {
		super(dataAccess);
		this.director = dataAccess.getElementString("director");
	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#AskEdit()
	 */
	@Override
	public void AskEdit() throws CustomException {
		super.AskEdit();

		String buffer;

		// Title
		System.out.print("- Director: ");
		buffer = Tools.readLineEdit(this.director);
		if (buffer.length() < 1)
			throw new CustomException(
					"Director name must at least have one character !");
		this.director = buffer;

	}

	/**
	 * @return The director for this DVD.
	 */
	public String getDirector() {
		return this.director;
	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#play()
	 */
	@Override
	public void play() {
		System.out.println("Ce media ne se lit pas");
	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#toMediaAccess()
	 */
	public DataAccess toMediaAccess() throws PathErrorException {
		DataAccess dataAccess = super.toMediaAccess();
		dataAccess.addElement("director", this.director);

		return dataAccess;
	}

	/**
	 * Méthode affichage pour un show
	 */
	public void affichage() {
		super.affichage();
		Tools.print(2, "Director    : " + this.director);
	}

	/*
	 * (non-Javadoc)
	 * @see projet.item.Item#toString()
	 */
	@Override
	public String toString() {
		return super.toString() + "Director:\"" + this.director + "\"";
	}
}
